package com.alkalinesolutions.json.core;

/**
 * Indicates a format error in the a piece of JSON text.
 * 
 * @author David Waite &lt;<a href='mailto:david@alkaline-solutions.com'>david@alkaline-solutions.com</a>&gt;
 */
public class SyntaxException extends JSONException {
	private static final long serialVersionUID = 1L;

	private final int p, cs;

	public SyntaxException(final int p, final int cs) {
		super();
		this.p = p;
		this.cs = cs;
	}

	@Override
	public String getMessage() {
		return String.format(
				Messages.getString("SyntaxException.message"), new Integer(p)); //$NON-NLS-1$
	}

	/**
	 * Zero-indexed offset of parsing failure within JSON text.
	 * 
	 * @return offset
	 */
	public int getErrorOffset() {
		return p;
	}

	/**
	 * State information of parser on failure. This value may differ across
	 * versions.
	 * 
	 * @return previous state
	 */
	public int getPreviousState() {
		return cs;
	}
}